﻿/**
 * @file action.c
 * @brief this is a brief description
 * @details this is the detail description.
 * @author fulong 
 * @data 9/2/2014
 * @version 1.0
 * @par Copyright (c):
 * @par First build
 *     version: fulong 
 *     data: 9/2/2014
 */
#include "action.h"
#include "../../dev/input.h"
#include "../../dev/output.h"
#include "../e2prom.h"
#include "../../dev/uart.h"
#include "../../lib/pid.h"

#include "board_action/board_action.h"
#ifdef __STM32
    #include "../../bsp/arch/stm32/stm32f1xx/STM32F10x_StdPeriph_Driver/inc/stm32f10x_gpio.h"
#endif

/*!< 程序代码选择 */
#define cProSelect read_action_param(101)

extern void feed_dog(void);
extern PID_struct pid;
static void   hal_action_output(void);

modbus_inner_var_struct modbus_inner_var[25];
uint8 param[PARAM_MAX];
action_output action_output_ctrl;

void mechine_action_init(void)
{
    uint8 i;
    for (i = 0; i < 25; i++)
    {
        modbus_inner_var[i].M_byte = 0;
    }
    for (i = 0; i < PARAM_MAX; i++)
    {
        feed_dog();
        param[i] = e2prom_read_random_byte(i);
    }
    action_output_ctrl.action_output_byte = 0x0;
	#ifdef PID_ENABLE
    pid_init();
	#endif
}
void mechine_action(void)
{
#ifndef __BOARD_TEST__
    switch (cProSelect)
    {
        case 0:
            board_action0();
            break;
        case 1:
            board_action1();
            break;
        default:
            break;
    }
#endif
    hal_action_output();
}
static void   hal_action_output(void)
{
#if OUTPUT_MAX_NUM > 0
    output(0, (BitAction)!Y00);
#endif
#if OUTPUT_MAX_NUM > 1
    output(1, (BitAction)!Y01);
#endif
#if OUTPUT_MAX_NUM > 2
    output(2, (BitAction)!Y02);
#endif
#if OUTPUT_MAX_NUM > 3
    output(3, (BitAction)!Y03);
#endif
#if OUTPUT_MAX_NUM > 4
    output(4, (BitAction)!Y04);
#endif
#if OUTPUT_MAX_NUM > 5
    output(5, (BitAction)!Y05);
#endif
#if OUTPUT_MAX_NUM > 6
    output(6, (BitAction)!Y06);
#endif
#if OUTPUT_MAX_NUM > 7
    output(7, (BitAction)!Y07);
#endif
#if OUTPUT_MAX_NUM > 8
    output(10, (BitAction)!Y10);
#endif
#if OUTPUT_MAX_NUM > 9
    output(11, (BitAction)!Y11);
#endif
#if OUTPUT_MAX_NUM > 10
    output(12, (BitAction)!Y12);
#endif
#if OUTPUT_MAX_NUM > 11
    output(13, (BitAction)!Y13);
#endif
#if OUTPUT_MAX_NUM > 12
    output(14, (BitAction)!Y14);
#endif
#if OUTPUT_MAX_NUM > 13
    output(15, (BitAction)!Y15);
#endif
#if OUTPUT_MAX_NUM > 14
    output(16, (BitAction)!Y16);
#endif
#if OUTPUT_MAX_NUM > 15
    output(17, (BitAction)!Y17);
#endif
#if OUTPUT_MAX_NUM > 16
    output(20, (BitAction)!Y20);
#endif
#if OUTPUT_MAX_NUM > 17
    output(21, (BitAction)!Y21);
#endif
}
